package com.android.smsmb.mui.adapters;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import com.android.smsmb.mui.PagerItem;

import java.util.ArrayList;

/**
 * Created by andrew on 7/11/14.
 */
public class MyPagerAdapter  extends FragmentPagerAdapter {

    private FragmentManager mFragmentManager;
    private ArrayList<PagerItem> mPagerItems;

    public MyPagerAdapter(FragmentManager fragmentManager, ArrayList<PagerItem> pagerItems) {
        super(fragmentManager);
        mFragmentManager = fragmentManager;
        mPagerItems = pagerItems;
    }

    public void setPagerItems(ArrayList<PagerItem> pagerItems) {
        if (mPagerItems != null)
            for (int i = 0; i < mPagerItems.size(); i++) {
                mFragmentManager.beginTransaction().remove(mPagerItems.get(i).getFragment()).commit();
            }
        mPagerItems = pagerItems;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return 2; // возвращает сколько всего табов
    }

    @Override
    public Fragment getItem(int i) {
        switch (i) {
            case 0:
                return mPagerItems.get(0).getFragment();
            case 1:
                return mPagerItems.get(1).getFragment();

        }
        //notifyDataSetChanged();
        return null;
    }
}
